// app.js
App({
  globalData: {
    doneCount: 0, // 全局共享的已完成数量
    totalCount:0
  },
  onLaunch() {
    // 初始化主题
    const savedTheme = wx.getStorageSync('currentTheme') || 'default';
    this.setTheme(savedTheme);
    const storedDone = wx.getStorageSync('done');
    this.globalData.doneCount = storedDone ? parseInt(storedDone) : 0;
    const totalCount = wx.getStorageSync('total');
    this.globalData.totalCount = totalCount ? parseInt(totalCount) : 0;
  },
  
  // 主题配置
  themes: {
    default: {
      name: '默认主题',
      mainColor: '#165dff',
      bgColor: '#f7f8fa',
      cardColor: '#ffffff',
      textColor: '#333333',
      subTextColor: '#999999',
      borderColor: '#eeeeee'
    },
    dark: {
      name: '深色主题',
      mainColor: '#3a71ff',
      bgColor: '#1a1a1a',
      cardColor: '#2c2c2c',
      textColor: '#f5f5f5',
      subTextColor: '#bbbbbb',
      borderColor: '#333333'
    },
    green: {
      name: '清新绿',
      mainColor: '#36d399',
      bgColor: '#f0fdf4',
      cardColor: '#ffffff',
      textColor: '#1e293b',
      subTextColor: '#64748b',
      borderColor: '#dcfce7'
    },
    purple: {
      name: '优雅紫',
      mainColor: '#9333ea',
      bgColor: '#faf5ff',
      cardColor: '#ffffff',
      textColor: '#374151',
      subTextColor: '#6b7280',
      borderColor: '#f3e8ff'
    }
  },
  
  // 设置主题
  setTheme(themeName) {
    this.globalData.currentTheme = this.themes[themeName];
    this.globalData.themeName = themeName;
    
    // 保存到本地
    wx.setStorageSync('currentTheme', themeName);
    
    // 通知所有页面更新主题
    if (this.themeUpdateCallback) {
      this.themeUpdateCallback(this.globalData.currentTheme);
    }
  },
  
  // 注册主题更新回调
  registerThemeUpdate(callback) {
    this.themeUpdateCallback = callback;
  },
  
  globalData: {
    currentTheme: null,
    themeName: 'default',
    baseUrl: 'http://127.0.0.1:8080', // 这里定义基础API路径
    userInfo: null
  }
})
